#!/usr/local/bin/php
<?php
require_once 'Log.php';

$options = getopt('n:');
if (isset($options['n'])) {
    $number = (int) $options['n'];
} else {
    $number = 1;
}

$logger = Log::factory('console', '', '', array(
    'lineFormat' => '[%1$s] [%3$s] %5$s(%6$s): %4$s',
    'timeFormat' => '%Y-%m-%d %H:%M:%S'
), PEAR_LOG_INFO);

$cmd = "ps -ef | grep 'op_stat_worker.php' | grep -vc 'grep op_stat_worker.php'";
$workerNumber = exec($cmd);
if ($workerNumber < $number) {
    for ($i = $workerNumber + 1; $i <= $number; $i++) {
        $cmd = "/opt/op/channels/opstat.sdo.com/daemon/op_stat_worker.php >>/var/log/opstat/op_stat_worker_$i.log";
        exec($cmd, $output, $ret);
        $logger->info("worker $i start successfully: ret-$ret");
    }
}